from django import forms

from web import models
from web.forms.bootstrap import BootStrapForm


class WikiModelForm(BootStrapForm, forms.ModelForm):

    def __init__(self, request, *args, **kwargs):
        super().__init__(*args, **kwargs)
        # 只显示当前项目的文章：找到需要的字段，重写
        total_data_list =[("","请选择"),]
        data_list = models.Wiki.objects.filter(project=request.tracer.project).values_list('id', 'title')
        total_data_list.extend(data_list)
        self.fields['parent'].choices = total_data_list

    class Meta:
        model = models.Wiki
        # 移除表单不需要显示的选项
        exclude = ['project','depth' ]
